﻿# ----------------------------------------------------------------------------- 
# Script:	Hyper-V_Toolbar.ps1
# Date:		2011-09-27 
# Version:	0.1
# Author:	Łukasz Kałużny lukasz.kaluzny@gmail.com
# Homepage: http://hypervtoolbar.codeplex.com/ 
# -----------------------------------------------------------------------------
#region ToolbarApps
$LinkPathArray = @()
#To add new program to toolbar uncomment line below and change Path_To_Exe with path to your exe
#$LinkPathArray += "Path_To_Exe"
$LinkPathArray += "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe"
$LinkPathArray += "C:\Windows\System32\cmd.exe"
$LinkPathArray += "C:\Windows\System32\taskmgr.exe"
$LinkPathArray += "C:\Windows\regedit.exe"
$LinkPathArray += "C:\Windows\System32\notepad.exe"
#Paste here your application

#endregion

#region Helpers

function Hide-PowerShell { 
    $null = $showWindowAsync::ShowWindowAsync((Get-Process –id $pid).MainWindowHandle, 2) 
}

function Create-Button{
	Param(
		[System.String]$LinkPath
		,[System.String]$IconPath = $LinkPath
	)
	$bt = New-Object System.Windows.Forms.Button
	$bt.Size = New-Object System.Drawing.Size(45,45)
	$bt.Image = [System.Drawing.Icon]::ExtractAssociatedIcon($IconPath).ToBitmap()
	$bt.Tag = $LinkPath
	#$objForm.Width += 30
	$bt.add_Click({
		Start-Process -FilePath $args[0].Tag
	} )
	return $bt
}

#endregion 

#region Using

$script:showWindowAsync = Add-Type –memberDefinition @” 
[DllImport("user32.dll")] 
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

#endregion

#region Create Form

$objForm = New-Object System.Windows.Forms.Form 
$objForm.Text = "Hyper-V Toolbar"
$objForm.Size = New-Object System.Drawing.Size(0,0) 
$objForm.AutoSize = $true
$objForm.StartPosition = "CenterScreen"
$Panel = New-Object System.Windows.Forms.FlowLayoutPanel
$Panel.FlowDirection = "LeftToRight"
$Panel.Dock = "Fill"
$Panel.AutoSize = $true
$objForm.Controls.Add($Panel)
foreach($item in $LinkPathArray)
{
	$Panel.Controls.Add((Create-Button -LinkPath $item))
}

#endregion

#region Show From

Hide-PowerShell
[void] $objForm.ShowDialog()

#endregion


